package com.cloud.cloudvideo.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cloud.cloudvideo.entity.ResultModel;
import com.cloud.cloudvideo.entity.SysPermission;
import com.cloud.cloudvideo.entity.TreePojo;
import com.cloud.cloudvideo.service.MenuService;

/**
 * 菜单管理
 * @author hussein
 *
 */
@Controller
@RequestMapping("menu")
public class MenuController {

	
	@Autowired
	private MenuService menuService;
	
	@RequestMapping("/tolist")
	public String menulist() {
		return "manager/menu/list";
	}
	
	
	@RequestMapping("/list")
	@ResponseBody
	public ResultModel<List<SysPermission>> list(){
		List<SysPermission> list = menuService.list();
		return ResultModel.successWithData(list, list.size());
	}
	
	
	@RequestMapping("/toAdd")
	public String toAdd(Model model) {
//		model.addAttribute("menu", new SysPermission());
//		model.addAttribute("pmenu", new SysPermission());
		return "manager/menu/add";
	}
	
	@RequestMapping("/toModify")
	public String toModify(Integer id,Model model) {
		Map<String,Object> map = menuService.menuInfo(id);
		model.addAttribute("menu", map.get("menu"));
		model.addAttribute("pmenu", map.get("pmenu"));
		return "manager/menu/add";
	}
	
	
	@RequestMapping("/add")
	@ResponseBody
	public ResultModel add(SysPermission permission) {
		menuService.modifyPermission(permission);
		return ResultModel.successWithNoData();
	}
	
	
	
	@RequestMapping("/treelist")
	@ResponseBody
	public ResultModel<List<TreePojo>> treelist() {
		List<TreePojo> list =   menuService.treelist();
		return ResultModel.successWithData(list,list.size());
	}
	  
	
	@RequestMapping("/totreelist")
	public String totreelist() {
		return "manager/menu/treelist";
	}
	
}
